package com.zhongkun.datahome.service.utils;

import org.apache.commons.lang3.StringUtils;

public class SensitiveUtil {

    public static String sensitiveMobile(String mobile) {
        if (StringUtils.isBlank(mobile)) {
            return "";
        }
        if (mobile.length() == 11) {
            mobile = String.format("%s****%s", mobile.substring(0, 3), mobile.substring(7));
            return mobile;
        }

        return mobile;
    }

    public static String sensitiveIdentifyNum(String identifyNum) {
        if (StringUtils.isBlank(identifyNum)) {
            return "";
        }
        if (identifyNum.length() == 18) {
            return String.format("%s********%s", identifyNum.substring(0, 6), identifyNum.substring(14));
        }

        return identifyNum;
    }

    /**
     * 隐藏名字，只展示姓，如：李**，王*，易***
     *
     * @param fullName 名字全称
     * @return string
     */
    public static String sensitiveLastName(String fullName) {
        if (StringUtils.isBlank(fullName)) {
            return StringUtils.EMPTY;
        }

        return StringUtils.rightPad(StringUtils.left(fullName, 1), StringUtils.length(fullName), "*");
    }

    public static String subLastMobile(String mobile) {
        if (StringUtils.isBlank(mobile)) {
            return StringUtils.EMPTY;
        }

        return StringUtils.right(mobile, 4);
    }
}
